#include "Vertex.h"

IDirect3DVertexDeclaration9* VertexPos::decl = 0;
IDirect3DVertexDeclaration9* VertexCol::decl = 0;
IDirect3DVertexDeclaration9* VertexTexCol::decl = 0;
IDirect3DVertexDeclaration9* VertexTex::decl = 0;
IDirect3DVertexDeclaration9* GrassVertex::decl = 0;

void InitAllVertexDeclaration()
{
	// VertexPos
	D3DVERTEXELEMENT9 vertexPosElement[] = 
	{
		{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		D3DDECL_END()
	};
	gd3dDevice->CreateVertexDeclaration(vertexPosElement, &VertexPos::decl);

	// VertexCol
	D3DVERTEXELEMENT9 vertexColElement[] =
	{
		{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};
	gd3dDevice->CreateVertexDeclaration(vertexColElement, &VertexCol::decl);

	// VertexTex
	D3DVERTEXELEMENT9 vertexTexElement[] =
	{
		{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		D3DDECL_END()
	};
	gd3dDevice->CreateVertexDeclaration(vertexTexElement, &VertexTex::decl);

	// VertexTexCol
	D3DVERTEXELEMENT9 vertexTexColElement[] =
	{
		{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		{0, 20, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};
	gd3dDevice->CreateVertexDeclaration(vertexTexColElement, &VertexTexCol::decl);

	D3DVERTEXELEMENT9 GrassVertexElements[] = 
	{
		{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
		{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
		{0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2},
		{0, 36, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};	
	HR(gd3dDevice->CreateVertexDeclaration(GrassVertexElements, &GrassVertex::decl));
}

void DestroyAllVertexDeclaration()
{
	ReleaseCOM(VertexPos::decl);
	ReleaseCOM(VertexCol::decl);
	ReleaseCOM(VertexTexCol::decl);
	ReleaseCOM(VertexTex::decl);
	ReleaseCOM(GrassVertex::decl);
}